home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.Stanford.EDU!microunity!toms
- From: toms@MicroUnity.com (Tom Sanders)
- Subject: Re: Help, best way to compare doubles
- Message-ID: <DLE3uF.yL@microunity.com>
- Sender: usenet@microunity.com (news id)
- Organization: MicroUnity Systems Engineering, Inc.
- References: <4da169$mm4@mercury.IntNet.net> <4dfdtl$phv@nntp.crl.com> <DLD5Kp.JME@eskimo.com>
- Date: Thu, 18 Jan 1996 18:39:50 GMT
-
- In article <DLD5Kp.JME@eskimo.com>, mag@eskimo.com (mAg) writes:
- |> In article <4dfdtl$phv@nntp.crl.com> (16 Jan 1996 05:43:17 GMT),
- |> bivey@ecf2.puc.edu says :
- |> >
- |> >Jeff Tomich (jtomich@IntNet.net) wrote:
- |> >: Looking for a way to compare doubles for equality.
- |> >
- |> >: thanks, Jeff
- |> >
- |> >The first question to ask is "how equal"? In general, one picks some
- |> >error limit, such as e = 1E-6; then uses it in this form:
- |> >
- |> > if (fabs(n1 - n2) < e) // then they are considered equal
- |> > else // they are considered different
- |> >
- |>
- |> "How equal" is irrelevant. "Equal to" comparison produces a boolean result
- |> True or False.
- |>
- |> '==' is good enough
- |>
-
- If any numeric computations have been performed on the 2 doubles '==' is
- inappropriate due to numeric computation errors. I have always preferred
- first rounding both operands to the same number of digits prior to a
- comparison. How many digits is very application dependent.
-
- Tom Sanders
-
-